package com.rose.lvye.spandemo;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

/**
 * 作者:	Rose
 * 业务名:
 * 功能说明:
 * 编写日期:	${date}
 */
public class SpanGridViewAdapter extends BaseAdapter {
    private int[] data;
    private Context context;

    public SpanGridViewAdapter(Context context, int []data) {
        this.data = data;
        this.context = context;
    }

    @Override
    public int getCount() {
        return data.length;
    }

    @Override
    public Object getItem(int position) {
        return data[position];
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        HoldView holdView;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.span_item , null);
            holdView = new HoldView();
            holdView.spanView = (ImageView)convertView.findViewById(R.id.imageView);
            convertView.setTag(holdView);
        }else{
            holdView = (HoldView)convertView.getTag();
        }
        holdView.spanView.setImageResource(data[position]);
        return convertView;
    }

    @Override
    public long getItemId(int position) {
        return data[position];
    }

    public static class HoldView {
        ImageView spanView;
    }
}
